#include "login_widget.h"
#include "ui_login_widget.h"

#include <QMessageBox>
#include <QApplication>

login_widget::login_widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::login_widget)
{
    ui->setupUi(this);

    // 设置窗口标题
    setWindowTitle("登录");

    ui->accout_edit->setMaxLength(20);// 设置账号最长输入20个字符
    ui->password_edit->setMaxLength(16);// 设置密码最长输入16个字符
    ui->password_edit->setEchoMode(QLineEdit::Password);// 设置密码回显模式

    face=new Form;
    connect(face,SIGNAL(returnPressed()),this,SLOT(show()));
}

login_widget::~login_widget()
{
    delete ui;
    delete face;
}


void login_widget::on_login_button_clicked()
{
    // 获取账号内容
    QString account = ui->accout_edit->text();
    if(account.isEmpty())
    {
        QMessageBox::warning(this,"警告","账号不能为空!");
        return;
    }

    // 获取密码内容
    QString password = ui->password_edit->text();
    if(password.isEmpty())
    {
        QMessageBox::warning(this,"警告","密码不能为空!");
        return;
    }

    // 验证账号密码是否正确
    if(account!="admin"||password!="123")
    {
        QMessageBox::warning(this,"警告","账号或密码错误!");
        return;
    }

    // 清除用户名密码
    ui->accout_edit->clear();
    ui->password_edit->clear();

    // 跳转到人脸打卡考勤界面
    // 关闭当前窗口
    this->close();
//    this->hide();
    // 显示人脸打卡考勤界面
    face->show();
}


void login_widget::on_exit_button_clicked()
{
    // 退出
    exit(0);
}
